package Chapter3;
import Chapter2.Node;

public class MyStack {
	Node top;
	
	public Node pop()
	{
		if(top != null)
		{
			Node preTop = top;
			top = top.Next;
			return preTop;
		}
		return null;
	}
	
	public void push(int item)
	{
		Node newNode = new Node(item);
		newNode.Next = top;
		top = newNode;
	}
	
	public Node peek()
	{
		return top;
	}
	
	public boolean isEmpty()
	{
		return (top == null);
	}
	
	public Node removeBottom()
	{
		MyStack tempStack = new MyStack();
		while(top.Next != null){
			tempStack.push(this.pop().value);
		}
		Node node = this.pop();
		while(tempStack.top != null){
			this.push(tempStack.pop().value);
		}
		return node;
	}
	
	public void checkStackResult()
	{
		Node node = top;
		while(node != null)
		{
			System.out.print(node.value + " ");
			node = node.Next;
		}
		System.out.println();
	}
	
//	public static void main(String args[]){
//		MyStack stack = new MyStack();
//		
//		stack.push(3);
//		stack.push(5);
//		
//		stack.push(7);
//		stack.checkStackResult();
//		Node node = stack.removeBottom();
//		
//		stack.checkStackResult();
//		System.out.print(node.value);
//	}
}
